package com.example.day01

import android.os.Bundle
import android.widget.SimpleAdapter
import android.widget.Spinner
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class SimpleMainActivity : AppCompatActivity() {

    class list(val img: Int, val name: String)

    val data = listOf(
        list(R.drawable.bj, "北京"),
        list(R.drawable.sh, "上海"),
        list(R.drawable.gz, "广州"),
        list(R.drawable.sz, "深圳"),
        list(R.drawable.hz, "杭州"),
        list(R.drawable.nj, "南京"),
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_simple_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val spinner: Spinner = findViewById(R.id.sp)
        spinner.adapter = SimpleAdapter(
            this,
            data.map {
                mapOf("img" to it.img, "name" to it.name)
            },
            R.layout.ic,
            arrayOf("img", "name"),
            intArrayOf(R.id.im, R.id.tex)
        )
    }
}